import xml.dom.minidom
import re

def init_plants(filename):
    xml_tree = xml.dom.minidom.parse(filename)
    
    #where to store information about each plant
    plants_dict = dict()
    
    #get all plants in the file 
    plants = xml_tree.getElementsByTagName("plant")
    for plant in plants:
        name = plant.getAttribute("name")
        
        #iterate through each property of this plant (growth rate etc) and store it in plant_info
        plant_info = dict()
        
        #store the properties in plant_info
        for property in plant.childNodes:
            #ignore whitespace nodes
            if ((property.nodeType is 3) and (re.search("\s*", property.nodeValue))):
                continue
            
            #make each property an int, if possible, otherwise leave it as a string
            try:
                plant_info[property.nodeName] = int(property.firstChild.nodeValue)
            except ValueError:
                plant_info[property.nodeName] = property.firstChild.nodeValue
            
        plant_info['name'] = name
        plants_dict[name] = plant_info
        
    return plants_dict
    